﻿using Holla.Core.Application.Commands;
using Holla.Core.Application.Queries;
using Holla.Infrastructure.Mediator.AspNetCore;

using Microsoft.AspNetCore.Mvc;

using System.Threading;
using System.Threading.Tasks;

namespace Holla.Core.Api.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class TodosController : ApiControllerBase
    {
        [HttpPost]
        public async Task<IActionResult> AddTodo(TodoCreateCommand command, CancellationToken cancellationToken)
        {
            var result = await Mediator
                .Send(command, cancellationToken)
                .ConfigureAwait(false);

            return Ok(result);
        }

        [HttpGet]
        public async Task<IActionResult> GetTodoList([FromQuery] TodoListQuery query, CancellationToken cancellationToken)
        {
            var result = await Mediator
                .Send(query, cancellationToken)
                .ConfigureAwait(false);

            return Ok(result);
        }
    }
}
